package service;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class MessageHandler {
        private ObjectOutputStream out;
        private ObjectInputStream in;
        
        public MessageHandler(ObjectOutputStream out, ObjectInputStream in){
                this.in = in;
                this.out = out;
        }
        
        public String sendMessage(final String msg) throws IOException {
                out.writeObject(msg);
                out.flush();
                return msg;
        }

        public String readMessage() throws IOException {
        String message = null;
        try {
                        message = (String) in.readObject();
                } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                }
                return message;
        }
}